﻿package com.duartepeixinho.pTween.core
{	
	import flash.utils.Dictionary;
	/**
	 * pTween v1.1
	 * @author Duarte Peixinho
	 */
	public class tweenObj
	{		
		// TweenObj Vars
		private var _duration:Number;
		private var _initTime:Number;
		private var _endTime:Number;
		private var _target:Object;
		private var _initParams:Object = new Object();
		private var _endParams:Object;
		private var _easing:String;
		private var _delay:Number = 0;
		private var _onComplete:Function;
		private var _onCompleteParams:Array;
		private var _onEnterFrame:Function;
		private var _onEnterFrameParams:Array;	
		private var _onStart:Function;
		private var _onStartParams:Array;
		private var _onStartDone:Boolean = true;
		private var _pauseInit:Number = 0;
		private var _pauseEnd:Number = 0;
		private var _pause:Boolean = false;
		private var _reverse:Boolean = false;
		private var _reverseTime:Number = 0;
		private var _byFrames:Boolean = false;
		private var _specialPropertiesOn:Boolean = false;	
		private var _specialProperties:Dictionary;
		private var _specialInitProperties:Dictionary;
		private var _autoAlpha:Boolean = false;
		private var _yoyo:Boolean = false;
		
		public function tweenObj(o:Object) 
		{
			_target = o;
		}
		/* PARAMS */
		public function set duration(t:Number):void {
			_duration = t;
		}
		public function get duration():Number {
			return _duration;
		}				
		public function set initTime(t:Number):void {
			_initTime = t;
		}		
		public function get initTime():Number {
			return _initTime + (_pauseEnd-_pauseInit);
		}	
		public function set endTime(t:Number):void {
			_endTime = t;
		}		
		public function get endTime():Number {			
			return _endTime + (_pauseEnd - _pauseInit);
		}			
		public function get target():Object {
			return _target;
		}
		public function get endParams():Object {
			return _endParams;
		}
		public function set endParams(o:Object):void {
			_endParams = o;
		}
		public function get initParams():Object {
			return _initParams;
		}
		public function set initParams(o:Object):void {
			_initParams = o;
		}	
		public function get easing():String {
			return _easing;
		}
		public function set easing(easing:String):void {
			_easing = easing;
		}
		public function get delay():Number {
			return _delay;
		}
		public function set delay(delay:Number):void {
			_delay = delay;
		}
		/* EVENTS */
		public function get onComplete():Function {
			return _onComplete;
		}
		public function set onComplete(onComplete:Function):void {
			_onComplete = onComplete;
		}
		public function set onCompleteParams(params:Array):void {
			_onCompleteParams = params;
		}
		public function get onCompleteParams():Array {
			return _onCompleteParams;
		}
		public function get onEnterFrame():Function {
			return _onEnterFrame;
		}
		public function set onEnterFrame(onEnterFrame:Function):void {
			_onEnterFrame = onEnterFrame;
		}
		public function set onEnterFrameParams(params:Array):void {
			_onEnterFrameParams = params;
		}
		public function get onEnterFrameParams():Array {
			return _onEnterFrameParams;
		}		
		public function get onStart():Function {
			return _onStart;
		}
		public function set onStart(onStart:Function):void {
			_onStart = onStart;
		}
		public function set onStartParams(params:Array):void {
			_onStartParams = params;
		}
		public function get onStartParams():Array {
			return _onStartParams;
		}			
		public function set onStartDone(onStartDone:Boolean):void {
			_onStartDone = onStartDone;
		}
		public function get onStartDone():Boolean {
			return _onStartDone;
		}
		/* PAUSE */
		public function set pauseInit(time:Number):void {
			_pauseInit += time;
			_pause = true;
		}
		public function get pauseInit():Number {
			return _pauseInit;
		}
		public function set pauseEnd(time:Number):void {
			_pauseEnd += time;
			_pause = false;
		}
		public function get pauseEnd():Number {
			return _pauseEnd;
		}
		public function get pause():Boolean {
			return _pause;
		}
		/* REVERSE */
		public function setReverse(reverse:Boolean, time:Number):void {
			_reverse = reverse;
			if (_reverse) {
				_reverseTime = time;
			}
			else {
				// actual time
				var timeAux:Number = (_reverseTime - (time - _reverseTime));	
				_initTime = (time - timeAux) + initTime;
				_endTime = _initTime + _duration;
				_reverseTime = 0;
			}
		}
		public function get reverse():Boolean {
			return _reverse;
		}
		public function get reverseTime():Number {
			return _reverseTime;
		}
		
		/* BY FRAMES */
		public function set tweenByFrames(frames:Boolean):void {
			_byFrames = frames;
		}		
		public function get tweenByFrames():Boolean {
			return _byFrames;
		}
		
		/* SPECIAL PROPERTIES */
		public function set specialPropertiesOn(specialProperties:Boolean):void {			
			if (specialProperties && !_specialPropertiesOn) {
				_specialProperties = new Dictionary();
				_specialInitProperties = new Dictionary();
			}
			_specialPropertiesOn = specialProperties;
		}		
		public function get specialPropertiesOn():Boolean {
			return _specialPropertiesOn;
		}		
		public function addSpecialProperty(property:String, params:Object):void {
			_specialProperties[property] = params;			
		}		
		public function get specialProperties():Dictionary {
			return _specialProperties;
		}
		public function get specialInitProperties():Dictionary {
			return _specialInitProperties;
		}
		public function set specialInitProperties(specialInitProperies:Dictionary):void {
			_specialInitProperties = specialInitProperies;
		}
		public function set autoAlpha(autoAlpha:Boolean):void {
			_autoAlpha = autoAlpha;
		}
		public function get autoAlpha():Boolean {
			return _autoAlpha;
		}
		public function set yoyo(yoyo:Boolean):void {
			_yoyo = yoyo;
		}
		public function get yoyo():Boolean {
			return _yoyo;
		}
	}
}